package top.wanzc.java.basic.sort;

import java.util.Arrays;

public class EasyChooseSortDemo {
	
	public static void main(String[] args) {
		int a[] = {49, 38, 65, 97, 76, 13, 27, 49, 0, 0, 0, 0, 0};
		// �ٶ�a�ĳ���Ϊ8
		sort(a, 8);
		System.out.println(Arrays.toString(a));
		
		
	}

	private static void sort(int[] a, int n) {
		for (int i = 0; i < n - 1; i++) {
			int min = i;
			for (int j = i + 1; j <= n - 1; j++) {
				if (a [j] < a[min]) {
					min = j;
				}
			}
			if (min != i) {
				swap(a, i, min);
			}
		}
	}

	private static void swap(int[] a, int i, int min) {
		int temp = a[i];
		a[i] = a[min];
		a[min] = temp;
	}
}
